<?php
  
  session_start();

  if (!isset($_SESSION['check']) || $_SESSION['check'] != true){
    header("location: index.php");
    /* Make sure that code below does not get executed when we redirect. */
    exit;
  }
?>

<!DOCTYPE HTML>
<html>
  <head>
    <title>Movie !!!</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
    <link href="datepicker/css/datepicker.css" rel="stylesheet">
    <script src="script/jquery-1.9.1.min.js"> </script>
    <script src="bootstrap/js/bootstrap.min.js"> </script>
    <script src="script/jquery.validate.js"> </script>
    <script src="datepicker/js/bootstrap-datepicker.js"> </script>


    <script>
		function openModalNamed(p) {
			var id = "#"+p;
			$(id).modal();
		}
		
    $(document).ready(function() {
      $("#dateOfBirth").datepicker();

      $("#artist-form").submit(function(e){
      alert("erere");
      var postData = $(this).serializeArray();
      var formURL = $(this).attr("action");
      $.ajax(
      {
          url : formURL,
          type: "POST",
          data : postData,
          success:function(data, textStatus, jqXHR)
          {
            alert(data);
          },
          error: function(jqXHR, textStatus, errorThrown)
          {
            //if fails     
          }
      });
      e.preventDefault();
    })

    })


  </script>
    

    <style type="text/css">
      .header {
        margin-top:20px;
      }
	 </style>
     
     <body>
    <div class="container">
      <!--marketplace banner photo -->
      <div class="header row-fluid">
        <div class="span7">
          <h1>Online Movie Rental System
            <small> CS2102 </small>
          </h1>
        </div>
        <div clas="span5">
        
        

          <div class=" pull-right" style="margin-top:20px;">
              <a class="btn btn-success" onclick="loadLoginModal(); return false;" style="<?php if($_SESSION['check'] == true) echo 'display: none'; ?>"> Log in </a>  
              <a class="btn" onclick="loadSignupModal(); return false;" style="<?php if($_SESSION['check'] == true) echo 'display: none'; ?>"> register </a> 
              <a href="#"><?php if(isset($_SESSION['check']) && $_SESSION['check'] == true) echo "User: "."$_SESSION[name]"; ?></a>
              <a class="btn" href="logout.php" style="<?php if (!isset($_SESSION['check']) || $_SESSION['check'] != true) echo 'display: none'; ?>"> log out </a> 
          </div>

          
        </div>
      </div>

      <div class="navbar">
        <div class="navbar-inner">
          <a class="brand" href="#">MOVIES!</a>
          <ul class="nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#">My bookings</a></li>
            <li><a href="#">All Movies</a></li>
          </ul>
        </div>
      </div>
      
      <a class="btn" onclick="openModalNamed('newArtist');">Add a new artist </a>
      <a class="btn" onclick="openModalNamed('newMovie');">Add a new movie </a>
    </div>
    
    
     <div class="modal hide fade" id="newArtist">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>Add new artist</h3>
      </div>
       <form action="artist.php" method="post" class="form-horizontal" id="artist-form" style="margin-bottom:0px">
      <div class="modal-body">
          <div class="control-group">
            <label class="control-label" for="name">name</label>
            <div class="controls">
              <input type="text" id="name" required name="name" placeholder="artist name?">
            </div>
          </div>

          <div class="control-group date" data-date-format="dd-mm-yyyy">
            <label class="control-label" for="dateOfBirth">Date of Birth</label>
            <div class="controls">
              <input type="text" id="dateOfBirth" required name="dateOfBirth" placeholder="Date of Birth?">
            </div>
          </div>
      </div>
      
      <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Close</a>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>
    </div>


    <div class="modal hide fade" id="newMovie">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>Add new movie</h3>
      </div>
       <form action="movie.php" method="post" class="form-horizontal" id="movie-form" style="margin-bottom:0px">
      <div class="modal-body">
          <div class="control-group">
            <label class="control-label" for="name">name</label>
            <div class="controls">
              <input type="text" id="name" required name="name" placeholder="movie name?">
            </div>
          </div>
           <div class="control-group">
             <label class="control-label">Select:</label>
             <div class="controls">
              <select>
                <?php 
                 $con = mysqli_connect("localhost","root","","movie");
                if(!$con)
                  die("Could not connect" . mysql_error());
                    $result = mysqli_query($con,"SELECT name FROM crew");
                    if ($result) {
                      while($row = mysqli_fetch_array($result)) {
                        echo "<option>".$row['name']."</option>";
                      }
                    }
                ?>
              </select>
            </div>
          </div>
      </div>
      <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Close</a>
        <button type="submit" class="btn btn-primary">Submit</button>
      </div>
      </form>
    </div>



 </body>